home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / bstcheat.zip / WEAPONS.QC < prev   
Text File  |  1996-08-29  |  27KB  |  1,270 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.         precache_sound ("items/suit.wav");
  26.         precache_sound ("items/suit2.wav");
  27.         precache_sound ("items/damage.wav");
  28.         precache_sound ("items/damage2.wav");
  29.         precache_sound ("items/damage3.wav");
  30.         precache_sound ("items/inv1.wav");
  31.         precache_sound ("items/inv2.wav");
  32.         precache_sound ("items/inv3.wav");
  33.  
  34. };
  35.  
  36. float() crandom =
  37. {
  38.     return 2*(random() - 0.5);
  39. };
  40.  
  41. /*
  42. ================
  43. W_FireAxe
  44. ================
  45. */
  46. void() W_FireAxe =
  47. {
  48.     local    vector    source;
  49.     local    vector    org;
  50.  
  51.     source = self.origin + '0 0 16';
  52.     traceline (source, source + v_forward*64, FALSE, self);
  53.     if (trace_fraction == 1.0)
  54.         return;
  55.     
  56.     org = trace_endpos - v_forward*4;
  57.  
  58.     if (trace_ent.takedamage)
  59.     {
  60.         trace_ent.axhitme = 1;
  61.         SpawnBlood (org, '0 0 0', 20);
  62.         T_Damage (trace_ent, self, self, 20);
  63.     }
  64.     else
  65.     {    // hit wall
  66.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  67.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  68.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  69.         WriteCoord (MSG_BROADCAST, org_x);
  70.         WriteCoord (MSG_BROADCAST, org_y);
  71.         WriteCoord (MSG_BROADCAST, org_z);
  72.     }
  73. };
  74.  
  75.  
  76. //============================================================================
  77.  
  78.  
  79. vector() wall_velocity =
  80. {
  81.     local vector    vel;
  82.     
  83.     vel = normalize (self.velocity);
  84.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  85.     vel = vel + 2*trace_plane_normal;
  86.     vel = vel * 200;
  87.     
  88.     return vel;
  89. };
  90.  
  91.  
  92. /*
  93. ================
  94. SpawnMeatSpray
  95. ================
  96. */
  97. void(vector org, vector vel) SpawnMeatSpray =
  98. {
  99.     local    entity missile, mpuff;
  100.     local    vector    org;
  101.  
  102.     missile = spawn ();
  103.     missile.owner = self;
  104.     missile.movetype = MOVETYPE_BOUNCE;
  105.     missile.solid = SOLID_NOT;
  106.  
  107.     makevectors (self.angles);
  108.  
  109.     missile.velocity = vel;
  110.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  111.  
  112.     missile.avelocity = '3000 1000 2000';
  113.     
  114. // set missile duration
  115.     missile.nextthink = time + 1;
  116.     missile.think = SUB_Remove;
  117.  
  118.     setmodel (missile, "progs/zom_gib.mdl");
  119.     setsize (missile, '0 0 0', '0 0 0');        
  120.     setorigin (missile, org);
  121. };
  122.  
  123. /*
  124. ================
  125. SpawnBlood
  126. ================
  127. */
  128. void(vector org, vector vel, float damage) SpawnBlood =
  129. {
  130.     particle (org, vel*0.1, 73, damage*2);
  131. };
  132.  
  133. /*
  134. ================
  135. spawn_touchblood
  136. ================
  137. */
  138. void(float damage) spawn_touchblood =
  139. {
  140.     local vector    vel;
  141.  
  142.     vel = wall_velocity () * 0.2;
  143.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  144. };
  145.  
  146.  
  147. /*
  148. ================
  149. SpawnChunk
  150. ================
  151. */
  152. void(vector org, vector vel) SpawnChunk =
  153. {
  154.     particle (org, vel*0.02, 0, 10);
  155. };
  156.  
  157. /*
  158. ==============================================================================
  159.  
  160. MULTI-DAMAGE
  161.  
  162. Collects multiple small damages into a single damage
  163.  
  164. ==============================================================================
  165. */
  166.  
  167. entity    multi_ent;
  168. float    multi_damage;
  169.  
  170. void() ClearMultiDamage =
  171. {
  172.     multi_ent = world;
  173.     multi_damage = 0;
  174. };
  175.  
  176. void() ApplyMultiDamage =
  177. {
  178.     if (!multi_ent)
  179.         return;
  180.     T_Damage (multi_ent, self, self, multi_damage);
  181. };
  182.  
  183. void(entity hit, float damage) AddMultiDamage =
  184. {
  185.     if (!hit)
  186.         return;
  187.     
  188.     if (hit != multi_ent)
  189.     {
  190.         ApplyMultiDamage ();
  191.         multi_damage = damage;
  192.         multi_ent = hit;
  193.     }
  194.     else
  195.         multi_damage = multi_damage + damage;
  196. };
  197.  
  198. /*
  199. ==============================================================================
  200.  
  201. BULLETS
  202.  
  203. ==============================================================================
  204. */
  205.  
  206. /*
  207. ================
  208. TraceAttack
  209. ================
  210. */
  211. void(float damage, vector dir) TraceAttack =
  212. {
  213.     local    vector    vel, org;
  214.     
  215.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  216.     vel = vel + 2*trace_plane_normal;
  217.     vel = vel * 200;
  218.  
  219.     org = trace_endpos - dir*4;
  220.  
  221.     if (trace_ent.takedamage)
  222.     {
  223.         SpawnBlood (org, vel*0.2, damage);
  224.         AddMultiDamage (trace_ent, damage);
  225.     }
  226.     else
  227.     {
  228.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  229.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  230.         WriteCoord (MSG_BROADCAST, org_x);
  231.         WriteCoord (MSG_BROADCAST, org_y);
  232.         WriteCoord (MSG_BROADCAST, org_z);
  233.     }
  234. };
  235.  
  236. /*
  237. ================
  238. FireBullets
  239.  
  240. Used by shotgun, super shotgun, and enemy soldier firing
  241. Go to the trouble of combining multiple pellets into a single damage call.
  242. ================
  243. */
  244. void(float shotcount, vector dir, vector spread) FireBullets =
  245. {
  246.     local    vector direction;
  247.     local    vector    src;
  248.     
  249.     makevectors(self.v_angle);
  250.  
  251.     src = self.origin + v_forward*10;
  252.     src_z = self.absmin_z + self.size_z * 0.7;
  253.  
  254.     ClearMultiDamage ();
  255.     while (shotcount > 0)
  256.     {
  257.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  258.  
  259.         traceline (src, src + direction*2048, FALSE, self);
  260.         if (trace_fraction != 1.0)
  261.             TraceAttack (4, direction);
  262.  
  263.                 shotcount = shotcount - 1;
  264.     }
  265.     ApplyMultiDamage ();
  266. };
  267.  
  268. /*
  269. ================
  270. W_FireShotgun
  271. ================
  272. */
  273. void() W_FireShotgun =
  274. {
  275.     local vector dir;
  276.  
  277.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  278.  
  279.     self.punchangle_x = -2;
  280.     
  281.         self.currentammo = self.ammo_shells = self.ammo_shells - 0;
  282.     dir = aim (self, 100000);
  283.     FireBullets (6, dir, '0.04 0.04 0');
  284. };
  285.  
  286.  
  287. /*
  288. ================
  289. W_FireSuperShotgun
  290. ================
  291. */
  292. void() W_FireSuperShotgun =
  293. {
  294.     local vector dir;
  295.  
  296.     if (self.currentammo == 1)
  297.     {
  298.         W_FireShotgun ();
  299.         return;
  300.     }
  301.         
  302.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  303.  
  304.     self.punchangle_x = -4;
  305.     
  306.         self.currentammo = self.ammo_shells = self.ammo_shells - 0;
  307.     dir = aim (self, 100000);
  308.     FireBullets (14, dir, '0.14 0.08 0');
  309. };
  310.  
  311.  
  312. /*
  313. ==============================================================================
  314.  
  315. ROCKETS
  316.  
  317. ==============================================================================
  318. */
  319.  
  320. void()    s_explode1    =    [0,        s_explode2] {};
  321. void()    s_explode2    =    [1,        s_explode3] {};
  322. void()    s_explode3    =    [2,        s_explode4] {};
  323. void()    s_explode4    =    [3,        s_explode5] {};
  324. void()    s_explode5    =    [4,        s_explode6] {};
  325. void()    s_explode6    =    [5,        SUB_Remove] {};
  326.  
  327. void() BecomeExplosion =
  328. {
  329.     self.movetype = MOVETYPE_NONE;
  330.     self.velocity = '0 0 0';
  331.     self.touch = SUB_Null;
  332.     setmodel (self, "progs/s_explod.spr");
  333.     self.solid = SOLID_NOT;
  334.     s_explode1 ();
  335. };
  336.  
  337. void() T_MissileTouch =
  338. {
  339.     local float    damg;
  340.  
  341.     if (other == self.owner)
  342.         return;        // don't explode on owner
  343.  
  344.     if (pointcontents(self.origin) == CONTENT_SKY)
  345.     {
  346.         remove(self);
  347.         return;
  348.     }
  349.  
  350.     damg = 100 + random()*20;
  351.     
  352.     if (other.health)
  353.     {
  354.         if (other.classname == "monster_shambler")
  355.             damg = damg * 0.5;    // mostly immune
  356.         T_Damage (other, self, self.owner, damg );
  357.     }
  358.  
  359.     // don't do radius damage to the other, because all the damage
  360.     // was done in the impact
  361.     T_RadiusDamage (self, self.owner, 120, other);
  362.  
  363. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  364.     self.origin = self.origin - 8*normalize(self.velocity);
  365.  
  366.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  367.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  368.     WriteCoord (MSG_BROADCAST, self.origin_x);
  369.     WriteCoord (MSG_BROADCAST, self.origin_y);
  370.     WriteCoord (MSG_BROADCAST, self.origin_z);
  371.  
  372.     BecomeExplosion ();
  373. };
  374.  
  375.  
  376.  
  377. /*
  378. ================
  379. W_FireRocket
  380. ================
  381. */
  382. void() W_FireRocket =
  383. {
  384.     local    entity missile, mpuff;
  385.     
  386.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 0;
  387.     
  388.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  389.  
  390.     self.punchangle_x = -2;
  391.  
  392.     missile = spawn ();
  393.     missile.owner = self;
  394.     missile.movetype = MOVETYPE_FLYMISSILE;
  395.     missile.solid = SOLID_BBOX;
  396.         
  397. // set missile speed    
  398.  
  399.     makevectors (self.v_angle);
  400.     missile.velocity = aim(self, 1000);
  401.     missile.velocity = missile.velocity * 1000;
  402.     missile.angles = vectoangles(missile.velocity);
  403.     
  404.     missile.touch = T_MissileTouch;
  405.     
  406. // set missile duration
  407.     missile.nextthink = time + 5;
  408.     missile.think = SUB_Remove;
  409.  
  410.         setmodel (missile, "progs/spike.mdl");
  411.     setsize (missile, '0 0 0', '0 0 0');        
  412.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  413. };
  414.  
  415. /*
  416. ===============================================================================
  417.  
  418. LIGHTNING
  419.  
  420. ===============================================================================
  421. */
  422.  
  423. /*
  424. =================
  425. LightningDamage
  426. =================
  427. */
  428. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  429. {
  430.     local entity        e1, e2;
  431.     local vector        f;
  432.     
  433.     f = p2 - p1;
  434.     normalize (f);
  435.     f_x = 0 - f_y;
  436.     f_y = f_x;
  437.     f_z = 0;
  438.     f = f*16;
  439.  
  440.     e1 = e2 = world;
  441.  
  442.     traceline (p1, p2, FALSE, self);
  443.     if (trace_ent.takedamage)
  444.     {
  445.         particle (trace_endpos, '0 0 100', 225, damage*4);
  446.         T_Damage (trace_ent, from, from, damage);
  447.         if (self.classname == "player")
  448.         {
  449.             if (other.classname == "player")
  450.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  451.         }
  452.     }
  453.     e1 = trace_ent;
  454.  
  455.     traceline (p1 + f, p2 + f, FALSE, self);
  456.     if (trace_ent != e1 && trace_ent.takedamage)
  457.     {
  458.         particle (trace_endpos, '0 0 100', 225, damage*4);
  459.         T_Damage (trace_ent, from, from, damage);
  460.     }
  461.     e2 = trace_ent;
  462.  
  463.     traceline (p1 - f, p2 - f, FALSE, self);
  464.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  465.     {
  466.         particle (trace_endpos, '0 0 100', 225, damage*4);
  467.         T_Damage (trace_ent, from, from, damage);
  468.     }
  469. };
  470.  
  471.  
  472. void() W_FireLightning =
  473. {
  474.     local    vector        org;
  475.  
  476.     if (self.ammo_cells < 1)
  477.     {
  478.         self.weapon = W_BestWeapon ();
  479.         W_SetCurrentAmmo ();
  480.         return;
  481.     }
  482.  
  483. // explode if under water
  484.     if (self.waterlevel > 1)
  485.     {
  486.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  487.                 self.ammo_cells = 200;
  488.         W_SetCurrentAmmo ();
  489.         return;
  490.     }
  491.  
  492.     if (self.t_width < time)
  493.     {
  494.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  495.         self.t_width = time + 0.6;
  496.     }
  497.         self.punchangle_x = -0;
  498.  
  499.         self.currentammo = self.ammo_cells = self.ammo_cells - 0;
  500.  
  501.     org = self.origin + '0 0 16';
  502.     
  503.     traceline (org, org + v_forward*600, TRUE, self);
  504.  
  505.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  506.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  507.     WriteEntity (MSG_BROADCAST, self);
  508.     WriteCoord (MSG_BROADCAST, org_x);
  509.     WriteCoord (MSG_BROADCAST, org_y);
  510.     WriteCoord (MSG_BROADCAST, org_z);
  511.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  512.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  513.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  514.  
  515.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  516. };
  517.  
  518.  
  519. //=============================================================================
  520.  
  521.  
  522. void() GrenadeExplode =
  523. {
  524.         T_RadiusDamage (self, self.owner, 400, world);
  525.  
  526.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  527.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  528.     WriteCoord (MSG_BROADCAST, self.origin_x);
  529.     WriteCoord (MSG_BROADCAST, self.origin_y);
  530.     WriteCoord (MSG_BROADCAST, self.origin_z);
  531.  
  532.     BecomeExplosion ();
  533. };
  534.  
  535. void() GrenadeTouch =
  536. {
  537.     if (other == self.owner)
  538.         return;        // don't explode on owner
  539.     if (other.takedamage == DAMAGE_AIM)
  540.     {
  541.         GrenadeExplode();
  542.         return;
  543.     }
  544.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  545.     if (self.velocity == '0 0 0')
  546.         self.avelocity = '0 0 0';
  547. };
  548.  
  549. /*
  550. ================
  551. W_FireGrenade
  552. ================
  553. */
  554. void() W_FireGrenade =
  555. {
  556.     local    entity missile, mpuff;
  557.     
  558.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 0;
  559.     
  560.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  561.  
  562.         self.punchangle_x = -0;
  563.  
  564.     missile = spawn ();
  565.     missile.owner = self;
  566.     missile.movetype = MOVETYPE_BOUNCE;
  567.     missile.solid = SOLID_BBOX;
  568.     missile.classname = "grenade";
  569.         
  570. // set missile speed    
  571.  
  572.     makevectors (self.v_angle);
  573.  
  574.     if (self.v_angle_x)
  575.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  576.     else
  577.     {
  578.         missile.velocity = aim(self, 10000);
  579.         missile.velocity = missile.velocity * 600;
  580.         missile.velocity_z = 200;
  581.     }
  582.  
  583.     missile.avelocity = '300 300 300';
  584.  
  585.     missile.angles = vectoangles(missile.velocity);
  586.     
  587.     missile.touch = GrenadeTouch;
  588.     
  589. // set missile duration change this to 2.5 if it don't work
  590.         missile.nextthink = time + 5;
  591.     missile.think = GrenadeExplode;
  592.  
  593.         setmodel (missile, "progs/lavaball.mdl");
  594.     setsize (missile, '0 0 0', '0 0 0');        
  595.     setorigin (missile, self.origin);
  596. };
  597.  
  598.  
  599. //=============================================================================
  600.  
  601. void() spike_touch;
  602. void() superspike_touch;
  603.  
  604.  
  605. /*
  606. ===============
  607. launch_spike
  608.  
  609. Used for both the player and the ogre
  610. ===============
  611. */
  612. void(vector org, vector dir) launch_spike =
  613. {
  614.     newmis = spawn ();
  615.     newmis.owner = self;
  616.     newmis.movetype = MOVETYPE_FLYMISSILE;
  617.     newmis.solid = SOLID_BBOX;
  618.  
  619.     newmis.angles = vectoangles(dir);
  620.     
  621.     newmis.touch = spike_touch;
  622.     newmis.classname = "spike";
  623.     newmis.think = SUB_Remove;
  624.     newmis.nextthink = time + 6;
  625.     setmodel (newmis, "progs/spike.mdl");
  626.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  627.     setorigin (newmis, org);
  628.  
  629.     newmis.velocity = dir * 1000;
  630. };
  631.  
  632. void() W_FireSuperSpikes =
  633. {
  634.     local vector    dir;
  635.     local entity    old;
  636.     
  637.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  638.         self.attack_finished = time + 0.1;
  639.         self.currentammo = self.ammo_nails = self.ammo_nails - 0;
  640.     dir = aim (self, 1000);
  641.     launch_spike (self.origin + '0 0 16', dir);
  642.     newmis.touch = superspike_touch;
  643.     setmodel (newmis, "progs/s_spike.mdl");
  644.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  645.         self.punchangle_x = -0;
  646. };
  647.  
  648. void(float ox) W_FireSpikes =
  649. {
  650.     local vector    dir;
  651.     local entity    old;
  652.     
  653.     makevectors (self.v_angle);
  654.     
  655.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  656.     {
  657.         W_FireSuperSpikes ();
  658.         return;
  659.     }
  660.  
  661.     if (self.ammo_nails < 1)
  662.     {
  663.         self.weapon = W_BestWeapon ();
  664.         W_SetCurrentAmmo ();
  665.         return;
  666.     }
  667.  
  668.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  669.         self.attack_finished = time + 0.1;
  670.         self.currentammo = self.ammo_nails = self.ammo_nails - 0;
  671.     dir = aim (self, 1000);
  672.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  673.  
  674.     self.punchangle_x = -2;
  675. };
  676.  
  677.  
  678.  
  679. .float hit_z;
  680. void() spike_touch =
  681. {
  682. local float rand;
  683.     if (other == self.owner)
  684.         return;
  685.  
  686.     if (other.solid == SOLID_TRIGGER)
  687.         return;    // trigger field, do nothing
  688.  
  689.     if (pointcontents(self.origin) == CONTENT_SKY)
  690.     {
  691.         remove(self);
  692.         return;
  693.     }
  694.     
  695. // hit something that bleeds
  696.     if (other.takedamage)
  697.     {
  698.         spawn_touchblood (9);
  699.         T_Damage (other, self, self.owner, 9);
  700.     }
  701.     else
  702.     {
  703.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  704.         
  705.         if (self.classname == "wizspike")
  706.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  707.         else if (self.classname == "knightspike")
  708.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  709.         else
  710.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  711.         WriteCoord (MSG_BROADCAST, self.origin_x);
  712.         WriteCoord (MSG_BROADCAST, self.origin_y);
  713.         WriteCoord (MSG_BROADCAST, self.origin_z);
  714.     }
  715.  
  716.     remove(self);
  717.  
  718. };
  719.  
  720. void() superspike_touch =
  721. {
  722. local float rand;
  723.     if (other == self.owner)
  724.         return;
  725.  
  726.     if (other.solid == SOLID_TRIGGER)
  727.         return;    // trigger field, do nothing
  728.  
  729.     if (pointcontents(self.origin) == CONTENT_SKY)
  730.     {
  731.         remove(self);
  732.         return;
  733.     }
  734.     
  735. // hit something that bleeds
  736.     if (other.takedamage)
  737.     {
  738.         spawn_touchblood (18);
  739.         T_Damage (other, self, self.owner, 18);
  740.     }
  741.     else
  742.     {
  743.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  744.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  745.         WriteCoord (MSG_BROADCAST, self.origin_x);
  746.         WriteCoord (MSG_BROADCAST, self.origin_y);
  747.         WriteCoord (MSG_BROADCAST, self.origin_z);
  748.     }
  749.  
  750.     remove(self);
  751.  
  752. };
  753.  
  754.  
  755. /*
  756. ===============================================================================
  757.  
  758. PLAYER WEAPON USE
  759.  
  760. ===============================================================================
  761. */
  762.  
  763. void() W_SetCurrentAmmo =
  764. {
  765.     player_run ();        // get out of any weapon firing states
  766.  
  767.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  768.     
  769.     if (self.weapon == IT_AXE)
  770.     {
  771.         self.currentammo = 0;
  772.         self.weaponmodel = "progs/v_axe.mdl";
  773.         self.weaponframe = 0;
  774.     }
  775.     else if (self.weapon == IT_SHOTGUN)
  776.     {
  777.         self.currentammo = self.ammo_shells;
  778.         self.weaponmodel = "progs/v_shot.mdl";
  779.         self.weaponframe = 0;
  780.         self.items = self.items | IT_SHELLS;
  781.     }
  782.     else if (self.weapon == IT_SUPER_SHOTGUN)
  783.     {
  784.         self.currentammo = self.ammo_shells;
  785.         self.weaponmodel = "progs/v_shot2.mdl";
  786.         self.weaponframe = 0;
  787.         self.items = self.items | IT_SHELLS;
  788.     }
  789.     else if (self.weapon == IT_NAILGUN)
  790.     {
  791.         self.currentammo = self.ammo_nails;
  792.         self.weaponmodel = "progs/v_nail.mdl";
  793.         self.weaponframe = 0;
  794.         self.items = self.items | IT_NAILS;
  795.     }
  796.     else if (self.weapon == IT_SUPER_NAILGUN)
  797.     {
  798.         self.currentammo = self.ammo_nails;
  799.         self.weaponmodel = "progs/v_nail2.mdl";
  800.         self.weaponframe = 0;
  801.         self.items = self.items | IT_NAILS;
  802.     }
  803.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  804.     {
  805.         self.currentammo = self.ammo_rockets;
  806.         self.weaponmodel = "progs/v_rock.mdl";
  807.         self.weaponframe = 0;
  808.         self.items = self.items | IT_ROCKETS;
  809.     }
  810.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  811.     {
  812.         self.currentammo = self.ammo_rockets;
  813.         self.weaponmodel = "progs/v_rock2.mdl";
  814.         self.weaponframe = 0;
  815.         self.items = self.items | IT_ROCKETS;
  816.     }
  817.     else if (self.weapon == IT_LIGHTNING)
  818.     {
  819.         self.currentammo = self.ammo_cells;
  820.         self.weaponmodel = "progs/v_light.mdl";
  821.         self.weaponframe = 0;
  822.         self.items = self.items | IT_CELLS;
  823.     }
  824.     else
  825.     {
  826.         self.currentammo = 0;
  827.         self.weaponmodel = "";
  828.         self.weaponframe = 0;
  829.     }
  830. };
  831.  
  832. float() W_BestWeapon =
  833. {
  834.     local    float    it;
  835.     
  836.     it = self.items;
  837.  
  838.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  839.         return IT_LIGHTNING;
  840.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  841.         return IT_SUPER_NAILGUN;
  842.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  843.         return IT_SUPER_SHOTGUN;
  844.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  845.         return IT_NAILGUN;
  846.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  847.         return IT_SHOTGUN;
  848.         
  849. /*
  850.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  851.         return IT_ROCKET_LAUNCHER;
  852.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  853.         return IT_GRENADE_LAUNCHER;
  854.  
  855. */
  856.  
  857.     return IT_AXE;
  858. };
  859.  
  860. float() W_CheckNoAmmo =
  861. {
  862.     if (self.currentammo > 0)
  863.         return TRUE;
  864.  
  865.     if (self.weapon == IT_AXE)
  866.         return TRUE;
  867.     
  868.     self.weapon = W_BestWeapon ();
  869.  
  870.     W_SetCurrentAmmo ();
  871.     
  872. // drop the weapon down
  873.     return FALSE;
  874. };
  875.  
  876. /*
  877. ============
  878. W_Attack
  879.  
  880. An attack impulse can be triggered now
  881. ============
  882. */
  883. void()    player_axe1;
  884. void()    player_axeb1;
  885. void()    player_axec1;
  886. void()    player_axed1;
  887. void()    player_shot1;
  888. void()    player_nail1;
  889. void()    player_light1;
  890. void()    player_rocket1;
  891.  
  892. void() W_Attack =
  893. {
  894.     local    float    r;
  895.  
  896.     if (!W_CheckNoAmmo ())
  897.         return;
  898.  
  899.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  900.     self.show_hostile = time + 1;    // wake monsters up
  901.  
  902.     if (self.weapon == IT_AXE)
  903.     {
  904.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  905.         r = random();
  906.         if (r < 0.25)
  907.             player_axe1 ();
  908.         else if (r<0.5)
  909.             player_axeb1 ();
  910.         else if (r<0.75)
  911.             player_axec1 ();
  912.         else
  913.             player_axed1 ();
  914.                 self.attack_finished = time + 0.35;
  915.     }
  916.     else if (self.weapon == IT_SHOTGUN)
  917.     {
  918.         player_shot1 ();
  919.         W_FireShotgun ();
  920.                 self.attack_finished = time + 0.05;
  921.     }
  922.     else if (self.weapon == IT_SUPER_SHOTGUN)
  923.     {
  924.         player_shot1 ();
  925.         W_FireSuperShotgun ();
  926.                 self.attack_finished = time + 0.05;
  927.     }
  928.     else if (self.weapon == IT_NAILGUN)
  929.     {
  930.         player_nail1 ();
  931.     }
  932.     else if (self.weapon == IT_SUPER_NAILGUN)
  933.     {
  934.         player_nail1 ();
  935.     }
  936.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  937.     {
  938.         player_rocket1();
  939.         W_FireGrenade();
  940.                 self.attack_finished = time + 0.1;
  941.     }
  942.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  943.     {
  944.         player_rocket1();
  945.         W_FireRocket();
  946.                 self.attack_finished = time + 0.1;
  947.     }
  948.     else if (self.weapon == IT_LIGHTNING)
  949.     {
  950.         player_light1();
  951.                 self.attack_finished = time + 0.01;
  952.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  953.     }
  954. };
  955.  
  956. /*
  957. ============
  958. W_ChangeWeapon
  959.  
  960. ============
  961. */
  962. void() W_ChangeWeapon =
  963. {
  964.     local    float    it, am, fl;
  965.     
  966.     it = self.items;
  967.     am = 0;
  968.     
  969.     if (self.impulse == 1)
  970.     {
  971.         fl = IT_AXE;
  972.     }
  973.     else if (self.impulse == 2)
  974.     {
  975.         fl = IT_SHOTGUN;
  976.         if (self.ammo_shells < 1)
  977.             am = 1;
  978.     }
  979.     else if (self.impulse == 3)
  980.     {
  981.         fl = IT_SUPER_SHOTGUN;
  982.         if (self.ammo_shells < 2)
  983.             am = 1;
  984.     }        
  985.     else if (self.impulse == 4)
  986.     {
  987.         fl = IT_NAILGUN;
  988.         if (self.ammo_nails < 1)
  989.             am = 1;
  990.     }
  991.     else if (self.impulse == 5)
  992.     {
  993.         fl = IT_SUPER_NAILGUN;
  994.         if (self.ammo_nails < 2)
  995.             am = 1;
  996.     }
  997.     else if (self.impulse == 6)
  998.     {
  999.         fl = IT_GRENADE_LAUNCHER;
  1000.         if (self.ammo_rockets < 1)
  1001.             am = 1;
  1002.     }
  1003.     else if (self.impulse == 7)
  1004.     {
  1005.         fl = IT_ROCKET_LAUNCHER;
  1006.         if (self.ammo_rockets < 1)
  1007.             am = 1;
  1008.     }
  1009.     else if (self.impulse == 8)
  1010.     {
  1011.         fl = IT_LIGHTNING;
  1012.         if (self.ammo_cells < 1)
  1013.             am = 1;
  1014.     }
  1015.  
  1016.     self.impulse = 0;
  1017.     
  1018.     if (!(self.items & fl))
  1019.     {    // don't have the weapon or the ammo
  1020.                 sprint (self, "you don't have that weapon, IDIOT!\n");
  1021.         return;
  1022.     }
  1023.     
  1024.     if (am)
  1025.     {    // don't have the ammo
  1026.                 sprint (self, "you don't have enough ammo.\n");
  1027.         return;
  1028.     }
  1029.  
  1030. //
  1031. // set weapon, set ammo
  1032. //
  1033.     self.weapon = fl;        
  1034.     W_SetCurrentAmmo ();
  1035. };
  1036.  
  1037. /*
  1038. ============
  1039. CheatCommand
  1040. ============
  1041. */
  1042. void() CheatCommand =
  1043. {
  1044.     if (deathmatch || coop)
  1045.         return;
  1046.  
  1047.     self.ammo_rockets = 100;
  1048.     self.ammo_nails = 200;
  1049.     self.ammo_shells = 100;
  1050.     self.items = self.items | 
  1051.         IT_AXE |
  1052.         IT_SHOTGUN |
  1053.         IT_SUPER_SHOTGUN |
  1054.         IT_NAILGUN |
  1055.         IT_SUPER_NAILGUN |
  1056.         IT_GRENADE_LAUNCHER |
  1057.         IT_ROCKET_LAUNCHER |
  1058.                 IT_ARMOR3;
  1059.  
  1060.     self.ammo_cells = 200;
  1061.     self.items = self.items | IT_LIGHTNING;
  1062.         self.armorvalue = 200;
  1063.  
  1064.         self.weapon = IT_LIGHTNING;
  1065.     self.impulse = 0;
  1066.     W_SetCurrentAmmo ();
  1067.         dprint ("You have used the Cheat Command.  You have all weapons, ammo, and best armor!\n");
  1068. };
  1069.  
  1070. /*
  1071. ============
  1072. CycleWeaponCommand
  1073.  
  1074. Go to the next weapon with ammo
  1075. ============
  1076. */
  1077. void() CycleWeaponCommand =
  1078. {
  1079.     local    float    it, am;
  1080.     
  1081.     it = self.items;
  1082.     self.impulse = 0;
  1083.     
  1084.     while (1)
  1085.     {
  1086.         am = 0;
  1087.  
  1088.         if (self.weapon == IT_LIGHTNING)
  1089.         {
  1090.             self.weapon = IT_AXE;
  1091.         }
  1092.         else if (self.weapon == IT_AXE)
  1093.         {
  1094.             self.weapon = IT_SHOTGUN;
  1095.             if (self.ammo_shells < 1)
  1096.                 am = 1;
  1097.         }
  1098.         else if (self.weapon == IT_SHOTGUN)
  1099.         {
  1100.             self.weapon = IT_SUPER_SHOTGUN;
  1101.             if (self.ammo_shells < 2)
  1102.                 am = 1;
  1103.         }        
  1104.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1105.         {
  1106.             self.weapon = IT_NAILGUN;
  1107.             if (self.ammo_nails < 1)
  1108.                 am = 1;
  1109.         }
  1110.         else if (self.weapon == IT_NAILGUN)
  1111.         {
  1112.             self.weapon = IT_SUPER_NAILGUN;
  1113.             if (self.ammo_nails < 2)
  1114.                 am = 1;
  1115.         }
  1116.         else if (self.weapon == IT_SUPER_NAILGUN)
  1117.         {
  1118.             self.weapon = IT_GRENADE_LAUNCHER;
  1119.             if (self.ammo_rockets < 1)
  1120.                 am = 1;
  1121.         }
  1122.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1123.         {
  1124.             self.weapon = IT_ROCKET_LAUNCHER;
  1125.             if (self.ammo_rockets < 1)
  1126.                 am = 1;
  1127.         }
  1128.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1129.         {
  1130.             self.weapon = IT_LIGHTNING;
  1131.             if (self.ammo_cells < 1)
  1132.                 am = 1;
  1133.         }
  1134.     
  1135.         if ( (self.items & self.weapon) && am == 0)
  1136.         {
  1137.             W_SetCurrentAmmo ();
  1138.             return;
  1139.         }
  1140.     }
  1141.  
  1142. };
  1143.  
  1144. /*
  1145. ============
  1146. ServerflagsCommand
  1147.  
  1148. Just for development
  1149. ============
  1150. */
  1151. void() ServerflagsCommand =
  1152. {
  1153.     serverflags = serverflags * 2 + 1;
  1154. };
  1155.  
  1156. // This is the Quad Cheat!
  1157. void() QuadCheat =
  1158. {
  1159.     if (deathmatch || coop)
  1160.         return;
  1161.     self.super_time = 1;
  1162.         self.super_damage_finished = time + 60;
  1163.     self.items = self.items | IT_QUAD;
  1164.         dprint ("You have Quad Damage and now go kick some bloody ass!\n");
  1165. };
  1166.  
  1167. // This is of course the Biosuit cheat!
  1168. void() Suit =
  1169. {
  1170.         if (deathmatch || coop)
  1171.                 return;
  1172.         self.rad_time = 1;
  1173.         self.radsuit_finished = time + 60;
  1174.         self.items = self.items | IT_SUIT;
  1175.         dprint ("You have the BioSuit and can now breathe in the water!\n");
  1176. };
  1177.  
  1178. // This is the Invisibilty Cheat!
  1179. void() Invis =
  1180. {
  1181.         if (deathmatch || coop)
  1182.                 return;
  1183.         self.invisible_time = 1;
  1184.         self.invisible_finished = time + 60;
  1185.         self.items = self.items | IT_INVISIBILITY;
  1186.         dprint ("You have the Ring of Shadows and can walk by monsters undetected!\n");
  1187. };
  1188.  
  1189. // This is the Key Cheat!
  1190. void() KeyCheat =
  1191. {
  1192.         if (deathmatch || coop)
  1193.                 return;
  1194.         self.items = self.items | IT_KEY1 | IT_KEY2;
  1195.         dprint ("You now have the keys!\n");
  1196. };
  1197. /*
  1198. ============
  1199. ImpulseCommands
  1200.  
  1201. ============
  1202. */
  1203. void() ImpulseCommands =
  1204. {
  1205.     if (self.impulse >= 1 && self.impulse <= 8)
  1206.         W_ChangeWeapon ();
  1207.  
  1208.     if (self.impulse == 9)
  1209.         CheatCommand ();
  1210.     if (self.impulse == 10)
  1211.         CycleWeaponCommand ();
  1212.     if (self.impulse == 11)
  1213.         ServerflagsCommand ();
  1214.  
  1215.         if (self.impulse == 12)
  1216.         QuadCheat ();
  1217.         if (self.impulse == 13)
  1218.                 Suit ();
  1219.         if (self.impulse == 14)
  1220.                 Invis ();
  1221.         if (self.impulse == 15)
  1222.                 KeyCheat ();
  1223.  
  1224.     self.impulse = 0;
  1225. };
  1226.  
  1227. /*
  1228. ============
  1229. W_WeaponFrame
  1230.  
  1231. Called every frame so impulse events can be handled as well as possible
  1232. ============
  1233. */
  1234. void() W_WeaponFrame =
  1235. {
  1236.     if (time < self.attack_finished)
  1237.         return;
  1238.  
  1239.     ImpulseCommands ();
  1240.     
  1241. // check for attack
  1242.     if (self.button0)
  1243.     {
  1244.         SuperDamageSound ();
  1245.         W_Attack ();
  1246.     }
  1247. };
  1248.  
  1249. /*
  1250. ========
  1251. SuperDamageSound
  1252.  
  1253. Plays sound if needed
  1254. ========
  1255. */
  1256. void() SuperDamageSound =
  1257. {
  1258.     if (self.super_damage_finished > time)
  1259.     {
  1260.         if (self.super_sound < time)
  1261.         {
  1262.             self.super_sound = time + 1;
  1263.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1264.         }
  1265.     }
  1266.     return;
  1267. };
  1268.  
  1269.  
  1270.